import time
import unittest

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://merchant.jsb.yhbyf.com/jsbAdmin/login?redirect=operatingStatements")
# el = driver.find_element(By.XPATH, '//input[@name="searchKey"]')

# 显示等待  第一种方法  lambda 密码函数
# pink = WebDriverWait(driver, 5).until(lambda x: x.find_element(By.NAME, 'searchKey'))
# pink.send_keys("温先生，房租交一下")


# 显示等待  第二种方法
# pink = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.NAME, 'searchKey')))
# pink.send_keys("温先生，房租交一下")

# 显示等待  第三种方法  这种使用的多
# pink = WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.NAME, 'searchKey')))
# pink.send_keys("温先生，房租交一下")

# locale = (By.NAME, 'searchKey')
# pink = WebDriverWait(driver, 5).until(EC.visibility_of_element_located(locale))
# pink.send_keys("温先生，房租交一下")


# driver.find_element(By.NAME, 'searchKey').send_keys("温先生，房租交一下")
# el = driver.find_element(By.XPATH, '//*[@name="searchKey"]').send_keys("温先生，房租交一下")
# time.sleep(1)
# driver.find_element(By.XPATH, '//*[@id="btnSearch"]').click()
# time.sleep(1)
# driver.find_element(By.LINK_TEXT, '温先生，房租交一下').click()
# # time.sleep(3)
# driver.find_element(By.LINK_TEXT, '点击阅读').click()
# time.sleep(5)

# driver.execute_script(
#     "arguments[0].setAttribute('style',arguments[1]);",
#     el,
#     'border:1px solid green;'
# )


# driver.execute_script(
#     "arguments[0].setAttribute('style', arguments[1]);",  # JavaScript 脚本
#     el,  # 第一个参数：要操作的网页元素（arguments[0]）
#     'border:1px solid green;'  # 第二个参数：要设置的 style 属性值（arguments[1]）
# )
# time.sleep(5)

# 输入登录手机号

loca = (By.XPATH, '//input[@placeholder="请输入手机号/登录账号"]')
pik = WebDriverWait(driver, 5).until(EC.visibility_of_element_located(loca))
pik.send_keys("18682300000")

# 输入登录密码
zai = (By.XPATH, '//input[@placeholder="请输入密码"]')
pik = WebDriverWait(driver, 5).until(EC.visibility_of_element_located(zai))
pik.send_keys("zby123456")
# 点击登录
deng = (By.XPATH, '//button[text()="登录"]')
WebDriverWait(driver, 5).until(EC.visibility_of_element_located(deng)).click()
# 选择商户号
time.sleep(5)
# xuan = (By.XPATH, '//*[@id="fullLoading"]/div/div/div[2]/div/div/div/div/div/div/div/div[18]')
# ActionChains(driver).scroll_to_element(xuan).perform()
# WebDriverWait(driver, 5).until(EC.visibility_of_element_located(xuan)).click()

xuan = driver.find_element(By.XPATH, '//*[@id="fullLoading"]/div/div/div[2]/div/div/div/div/div/div/div/div[3]')
ActionChains(driver).scroll_to_element(xuan).perform()
xuan.click()

time.sleep(5)

xuaning = driver.find_element(By.XPATH,
                              '//*[@id="fullLoading"]/section/section/section/section/div/div/ul/li/div/div[2]/span')

xuaning.text
print("你是的值是",xuaning)

# driver.find_element(By.XPATH, '').click()
# WebDriverWait(driver, 5).until(EC.visibility_of_element_located(xuan)).click()

# 选择数据中心
# shu = (By.XPATH, '//span[text()="数据中心"]')
# element = WebDriverWait(driver, 5).until(EC.visibility_of_element_located(shu))
# element.click()

# 选择经营报表
# jing = (By.XPATH, '//span[text()="顾客报表"]')
# elementing = WebDriverWait(driver, 5).until(EC.visibility_of_element_located(jing))
# elementing.click()
#
# time.sleep(4)
# # 选择自定义
# yi = (By.XPATH, '//span[text()="自定义"]')
# ding = WebDriverWait(driver, 5).until(EC.visibility_of_element_located(yi))
# ding.click()
# time.sleep(4)
# cha = (By.CSS_SELECTOR, '.arco-picker-suffix-icon')
# dingcha = WebDriverWait(driver, 5).until(EC.visibility_of_element_located(cha))
# dingcha.click()
#
# time.sleep(4)

# 选择日期
# rqi = (By.XPATH, '//input[@placeholder="开始日期"]')
# dingrqi = WebDriverWait(driver, 5).until(EC.visibility_of_element_located(rqi))
# dingrqi.send_keys("2025-8-9 5:00:00")
# time.sleep(10)
# 开始时间
# rqi = driver.find_element(By.XPATH, '//div[contains(@class, "arco-picker-input-active")]//input')
# rqi = driver.find_element(By.XPATH, '//input[@placeholder="开始日期"]')
# rqi.click()
# rqi.clear()
# rqi.send_keys("2025-1-0")
# time.sleep(4)
# # 结束时间
# # jiesu = (By.XPATH, '//input[@placeholder="开始日期"]')
# # jie = WebDriverWait(driver, 5).until(EC.visibility_of_element_located(jiesu))
# # jie.send_keys("2025-8-9 23:59:59")
# # time.sleep(6)
# jie = driver.find_element(By.XPATH, '//input[@placeholder="结束日期"]')
# jie.click()
# jie.click()
# jie.send_keys("2025-12-30")
# time.sleep(10)

# try:
#     # 调试开始日期
#     start_date = WebDriverWait(driver, 10).until(
#         EC.element_to_be_clickable((By.XPATH, '//input[@placeholder="开始日期"]'))
#     )
#     start_date.click()
#     # start_date.clear()
#     start_date.send_keys("2025-01-01")
#     # print("成功输入开始日期")
#
#     # 调试结束日期
#     end_date = driver.find_element(By.XPATH, '//input[@placeholder="结束日期"]')
#     end_date.click()
#     # end_date.clear()
#     end_date.send_keys("2025-08-10")
#     # print("成功输入结束日期")
#
# except Exception as e:
#     print(f"出现错误: {str(e)}")
#     # 可以添加截图帮助调试
#     # driver.save_screenshot("error.png")

# time.sleep(10)
#
# button = driver.find_element(By.XPATH, '/html/body/div[5]/div/div/div/div/div[2]/div/button')
# button.click()
#
# time.sleep(8)
#
# driver.find_element(By.XPATH, '//button[text()=" 搜索"]').click()

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec

# class Ttsting():
#     def __init__(self, driver):
#         self.driver = driver
#         self.driver = WebDriverWait(driver, 5)
#
#     def open(self, url):
#         self.driver.get(url)
#
#     def locator_with_wait(self, name, value):
#         locator = (name, value)
#         el = self.driver.until(ec.visibility_of_element_located(locator))
#         self.locator_yanshe(el)
#         return el
#
#     def locator_yanshe(self, el):
#         self.driver.execute_script(
#             "arguments[0].setAttribute('style',arguments[1]);",
#             el,
#             'border:1px solid green;'
#         )
#
#     def one_click(self, name, value):
#         self.locator_with_wait(name, value).click()
#
#     def one_input(self, name, value, center):
#         self.locator_with_wait(name, value).send_keys("center")
#
#     def leep(self, center):
#         self.time.sleep(center)
#
#     def iframe_que(self, center):
#         self.driver.switch_to.frame(center)
#
#     def iframe_tui(self, center):
#         self.driver.switch_to.default_content(center)
